//
//  SubscribeInfoViewController.m
//  suRead
//
//  Created by lidi on 2018/11/30.
//  Copyright © 2018 bao. All rights reserved.
//

#import "SubscribeInfoViewController.h"
#import "M_SubscribeInfo.h"
#import "M_Subscribe.h"
#import "Masonry.h"
#import "UIControl+Blocks.h"
#import "UIImageView+WebCache.h"

@interface SubscribeInfoViewController ()

@end

@implementation SubscribeInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    __weak typeof(self) weak_self = self;
    
    //头部导航栏
    UIView *navigationBarView = [UIView new];
    navigationBarView.backgroundColor = [[UIColor alloc] initWithRed:190.0f / 255.0f green:30.0f / 255.0f blue:30.0f / 255.0f alpha:1];
    [self.view addSubview:navigationBarView];
    [navigationBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(navigationBarView.superview);
        if (iPhoneX) {
            make.height.equalTo(@88.0f);
        } else {
            make.height.equalTo(@64.0f);
        }
    }];
    
    UIView *titleViewContainer = [UIView new];
    [navigationBarView addSubview:titleViewContainer];
    [titleViewContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(titleViewContainer.superview);
        make.height.equalTo(@44.0f);
    }];
    
    //返回
    UIButton *buttonBack = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonBack.tintColor = [UIColor whiteColor];
    [buttonBack setImage:[[UIImage imageNamed:@"button_backward"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    [titleViewContainer addSubview:buttonBack];
    [buttonBack addActionForControlEvents:UIControlEventTouchUpInside usingBlock:^(UIControl *sender, UIEvent *event) {
        [weak_self.navigationController popViewControllerAnimated:YES];
    }];
    [buttonBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(buttonBack.superview).offset(15.0);
        make.top.bottom.equalTo(buttonBack.superview);
        make.width.equalTo(@44.0f);
    }];
    
    //订阅号信息
    UIView *header = [UIView new];
    [self.view addSubview:header];
    [header mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(header.superview);
        make.top.equalTo(navigationBarView.mas_bottom);
        make.height.equalTo(@80.0f);
    }];
    
    UIImageView *imageViewIcon = [UIImageView new];
    imageViewIcon.layer.cornerRadius = 20.0f;
    imageViewIcon.layer.masksToBounds = true;
    [imageViewIcon sd_setImageWithURL:[NSURL URLWithString:self.info.f_service_img] placeholderImage:nil];
    [header addSubview:imageViewIcon];
    [imageViewIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.left.equalTo(imageViewIcon.superview).offset(30.0f);
        make.centerY.equalTo(imageViewIcon.superview);
    }];
    
    UILabel *labelName = [UILabel new];
    labelName.text = self.info.f_service_name;
    labelName.font = [UIFont fontWithName:@"FZBIAOYSJW--GB1-0" size:17.0f];
    labelName.textColor = [UIColor blackColor];
    [header addSubview:labelName];
    [labelName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageViewIcon.mas_right).offset(15.0f);
        make.top.equalTo(labelName.superview).offset(20.0f);
    }];
    
    if ([self.info.f_service_cert isEqualToString:@"1"]) {
        UIImageView *iconv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_v"]];
        [header addSubview:iconv];
        [iconv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(labelName.mas_right).offset(10.0);
            make.size.mas_equalTo(CGSizeMake(15, 15));
            make.centerY.mas_equalTo(labelName.mas_centerY);
        }];
    }
    
    UILabel *labelCount = [UILabel new];
    labelCount.text = [NSString stringWithFormat:@"文章%@篇",self.info.f_service_count];
    labelCount.font = [UIFont fontWithName:@"FZBIAOYSJW--GB1-0" size:11.0f];
    labelCount.textColor = [UIColor blackColor];
    [header addSubview:labelCount];
    [labelCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageViewIcon.mas_right).offset(15.0f);
        make.top.equalTo(labelName.mas_bottom).offset(5.0f);
    }];
    
    UIView *line = [UIView new];
    line.backgroundColor = [UIColor grayColor];
    [self.view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(line.superview).offset(30.0f);
        make.right.equalTo(line.superview).offset(-30.0f);
        make.top.equalTo(header.mas_bottom);
        make.height.equalTo(@1.0f);
    }];
    
    UILabel *introTitle = [UILabel new];
    introTitle.text = @"介绍";
    introTitle.font = [UIFont fontWithName:@"FZBIAOYSJW--GB1-0" size:17.0f];
    introTitle.textColor = [UIColor darkTextColor];
    [self.view addSubview:introTitle];
    [introTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(introTitle.superview).offset(30.0f);
        make.top.equalTo(line.mas_bottom).offset(15.0);
    }];
    
    UILabel *intro = [UILabel new];
    intro.text = self.info.f_service_desc;
    intro.font = [UIFont fontWithName:@"FZBIAOYSJW--GB1-0" size:15.0f];
    intro.numberOfLines = 0;
    intro.textColor = [UIColor lightGrayColor];
    [self.view addSubview:intro];
    [intro mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(intro.superview).offset(30.0f);
        make.top.equalTo(introTitle.mas_bottom).offset(5.0);
        make.right.equalTo(intro.superview).offset(-30.0f);
    }];
    
    UILabel *nameTitle = [UILabel new];
    nameTitle.text = @"账号主体";
    nameTitle.font = [UIFont fontWithName:@"FZBIAOYSJW--GB1-0" size:17.0f];
    nameTitle.textColor = [UIColor darkTextColor];
    [self.view addSubview:nameTitle];
    [nameTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameTitle.superview).offset(30.0f);
        make.top.equalTo(intro.mas_bottom).offset(30.0);
    }];
    
    UILabel *name = [UILabel new];
    name.text = self.info.f_service_company;
    name.font = [UIFont fontWithName:@"FZBIAOYSJW--GB1-0" size:15.0f];
    name.numberOfLines = 0;
    name.textColor = [UIColor lightGrayColor];
    [self.view addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(name.superview).offset(30.0f);
        make.top.equalTo(nameTitle.mas_bottom).offset(5.0);
        make.right.equalTo(name.superview).offset(-30.0f);
    }];
}

@end
